/**
 * Created by Administrator on 2016/12/22.
 */


/*日期选择*/
// 仅选择日期
$(".form-date").datetimepicker(
    {
        language: "zh-CN",
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0,
        format: "yyyy-mm-dd"
    });
var oUrl = `http://192.168.59.3:8082/console/shopping/order?buyerCompanyId=${1}&serializedId=${1}&shopId=${1}&projectCode=${1}&teamId=${1}&buyType=${1}&merchandiseType=${3}&startTime=${'2016-06-06'}&endTime=${'2016-07-07'}&pageNum=1&pageSize=10`;
var oUrl2 = `http://192.168.59.3:8082/console/shopping/order?buyerCompanyId=${1}&serializedId=${1}&shopId=${1}&projectCode=${1}&teamId=${1}&buyType=${1}&merchandiseType=${3}&startTime=${'2016-06-06'}&endTime=${'2016-07-07'}&pageNum=1&pageSize=10`;

$(function () {
    /*初始化*/
    init();
});

function init(){
    $('#workTable').bootstrapTable({
        method : 'post',  //发送方式
        url : oUrl,
        onLoadSuccess : function(){
            oSearch.click(oSearchFun);/*点击查询函数*/
            oEmpty.click(oEmptyFun);/*查询条件清空*/
        }
    })
}

/*订单条件查询*/
var
    oSerializedId = $('#serializedId'),
    oCategoryName = $('#categoryName'),
    oMerchandiseCode = $('#merchandiseCode'),
    oSearch = $('#search'),
    oEmpty = $('#empty');
var
    oSerializedIdVal = '',
    oCategoryNameVal = '',
    oMerchandiseCodeVal = '',
    oData = '';




/*按条件搜索*/
function oSearchFun(){
    oSerializedIdVal = oSerializedId.val();
    oCategoryNameVal = oCategoryName.val();
    oMerchandiseCodeVal = oMerchandiseCode.val();

    oData = {
        "serializedId": oSerializedIdVal,
        "categoryName": oCategoryNameVal,
        "merchandiseCode": oMerchandiseCodeVal
    };//如果 接口改正更新了  可以直接使用get 拼接

    //$.get(`http://192.168.59.3:8082/console/shopping/order?buyerCompanyId=${1}&serializedId=${1}&shopId=${1}&projectCode=${1}&teamId=${1}&buyType=${1}&merchandiseType=${3}&startTime=${'2016-06-06'}&endTime=${'2016-07-07'}&pageNum=1&pageSize=10`);
    $.ajax({
        type : 'get',
        url : oUrl2,
        dataType : 'json',
        contentType : 'application/json',
        data:JSON.stringify(oData),
        success : function (data){
            oData1 = responseHandler(data);
            $("#workTable").bootstrapTable('load',oData1);
        },
        error : function (err){
            console.log('错误');
        }
    })
}
/*清空条件*/
function oEmptyFun(){
    oSerializedId.val('');
    oCategoryName.val('');
    oMerchandiseCode.val('');
    $("#workTable").bootstrapTable('refresh',oUrl);
}

function responseHandler(res){
    console.log(res);
    var needData = {
        rows: res.data.list,
        total: res.data.total
    };

    return needData;
}

function indexFmt(val,row,index){
    return index+1;
}

function workTableQuery(params){
    params["pageNum"] = (params.offset / params.limit) + 1;
    params.pageSize = params.limit;
    return params;
}

